﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using YunSpace.Application.SiteMgr;
using YunSpace.Core;

namespace YunSpace.Web.Controllers
{
    public class TestController : Controller
    {
        private PdfApp pdfApp = new PdfApp();
        private readonly string _toSavePdfDirectory = Configs.GetValue("Pdf.ToSaveDirectory");

        // GET: Test
        public ActionResult Index()
        {
            return View();
        }

        public ActionResult DownloadPdf(string siteId = "01386bd6d8e091c2ab4c7c7de644d37b")
        {


            var fileName = Guid.NewGuid() + ".pdf";
            var path = $"{_toSavePdfDirectory}/{DateTime.Now:yyyyMMdd}/";

            if (!Directory.Exists(path))
            {
                Directory.CreateDirectory(path);
            }

            pdfApp.CreateSitePdf(path + fileName, Server.MapPath("~") + "/Download/Images/", siteId);

            return File(path + fileName, "text/plain", fileName);
        }
    }
}